<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Multi-file Upload</title>
    <style>
        body {
            font-family: Arial, sans-serif;
        }

        .upload-area {
            width: 100%;
            max-width: 600px;
            margin: 50px auto;
            padding: 20px;
            border: 2px dashed #ccc;
            border-radius: 10px;
            text-align: center;
            transition: background-color 0.2s ease;
        }

        .upload-area.dragover {
            background-color: #e0e0e0;
        }
    </style>
</head>

<body>
    <div class="upload-area" id="upload-area">
        <h2>Drag and drop files here</h2>
        <p>or</p>
        <input type="file" id="file-upload" multiple>
        <button onclick="uploadFiles()">Upload Files</button>
    </div>
    <div id="message"></div>

    <script>
        const uploadArea = document.getElementById('upload-area');
        const fileInput = document.getElementById('file-upload');

        uploadArea.addEventListener('dragover', (event) => {
            event.preventDefault();
            uploadArea.classList.add('dragover');
        });

        uploadArea.addEventListener('dragleave', () => {
            uploadArea.classList.remove('dragover');
        });

        uploadArea.addEventListener('drop', (event) => {
            event.preventDefault();
            uploadArea.classList.remove('dragover');
            const files = event.dataTransfer.files;
            fileInput.files = files;
        });

        function uploadFiles() {
            const files = fileInput.files;
            const formData = new FormData();
            for (let i = 0; i < files.length; i++) {
                formData.append('files', files[i], files[i].name);
            }

            fetch('/uploadfiles/', {
                method: 'POST',
                body: formData
            }).then(response => response.json())
                .then(data => {
                    document.getElementById('message').innerText = data.message;
                })
                .catch(error => {
                    document.getElementById('message').innerText = 'Error uploading files';
                });
        }

    </script>
</body>

</html>